<!--
 * @Descripttion: (OP70产品入夹具/dc_op70_record)
 * @Author: (admin)
 * @Date: (2025-02-28)
-->
<template>
    <div>
      <el-form :model="queryParams" label-position="right" inline ref="queryRef" v-show="showSearch" @submit.prevent>
        <el-form-item  label="盖板码" prop="coverCode">
            <el-input v-model="queryParams.coverCode" placeholder="" clearable style="width: 240px" @keyup.enter="handleQuery" />
          </el-form-item>
      <el-form-item  :label="$t('op30.col-1')" prop="bottomPlateCode">
            <el-input v-model="queryParams.bottomPlateCode" placeholder="" clearable style="width: 240px" @keyup.enter="handleQuery" />
          </el-form-item>
        <el-form-item>
          <el-button icon="search" type="primary" @click="handleQuery">{{ $t('btn.search') }}</el-button>
          <el-button icon="refresh" @click="resetQuery">{{ $t('btn.reset') }}</el-button>
        </el-form-item>
      </el-form>
      <!-- 工具区域 -->
      <el-row :gutter="15" class="mb10">
        <el-col :span="1.5">
          <!-- <el-button type="primary" v-hasPermi="['dcop70record:add']" plain icon="plus" @click="handleAdd">
            {{ $t('btn.add') }}
          </el-button> -->
        </el-col>
        <right-toolbar v-model:showSearch="showSearch" @queryTable="getList" :columns="columns"></right-toolbar>
      </el-row>
  
      <el-table
        :data="dataList"
        v-loading="loading"
        ref="table"
        border
        header-cell-class-name="el-table-header-cell"
        highlight-current-row
        @sort-change="sortChange"
        >
        <el-table-column prop="id" label="Id" align="center" v-if="columns.showColumn('id')"/>
        <el-table-column prop="coverCode" label="盖板码" width="150" align="center" :show-overflow-tooltip="true" v-if="columns.showColumn('coverCode')"/>
      <el-table-column prop="bottomPlateCode" label="底板码	" width="150" align="center" v-if="columns.showColumn('bottomPlateCode')"/>
      <el-table-column prop="totalResult" label="总结果	" width="100" align="center" :show-overflow-tooltip="true" />

        <el-table-column prop="fixtureId" label="夹具编号	" width="100" align="center" :show-overflow-tooltip="true" v-if="columns.showColumn('fixtureId')"/>

        
        <el-table-column prop="maxPressure" label="最大压力" width="100" align="center" v-if="columns.showColumn('maxPressure')"/>
       
        <el-table-column prop="weldingWireGap" label="焊丝间隙" width="100" align="center" v-if="columns.showColumn('weldingWireGap')"/>
        <el-table-column prop="pressingHeight" label="压装高度	" width="100" align="center" v-if="columns.showColumn('pressingHeight')"/>
        <el-table-column prop="misalignmentX" label="错位度 X" width="100" align="center" v-if="columns.showColumn('misalignmentX')"/>
        <el-table-column prop="misalignmentY" label="错位度 Y" width="100" align="center" v-if="columns.showColumn('misalignmentY')"/>
        <el-table-column prop="indentationDefect" label="内陷缺陷" width="100" align="center" v-if="columns.showColumn('indentationDefect')"/>
        <el-table-column prop="toolingGapUpper" label="工装间隙上" width="100" align="center" v-if="columns.showColumn('toolingGapUpper')"/>
        <el-table-column prop="toolingGapLower" label="工装间隙下" width="100" align="center" v-if="columns.showColumn('toolingGapLower')"/>
       
        <el-table-column prop="createdTime" label="创建时间" width="160" :show-overflow-tooltip="true"  v-if="columns.showColumn('createdTime')"/>
        
      </el-table>
      <pagination :total="total" v-model:page="queryParams.pageNum" v-model:limit="queryParams.pageSize" @pagination="getList" />
  
  
      <!-- 添加或修改OP70产品入夹具对话框 -->
      <el-dialog :title="title" :lock-scroll="false" v-model="open" >
        <el-form ref="formRef" :model="form" :rules="rules" label-width="100px">
          <el-row :gutter="20">
              
            <el-col :lg="12" v-if="opertype != 1">
              <el-form-item label="Id" prop="id">
                <el-input-number v-model.number="form.id" controls-position="right" placeholder="请输入Id" :disabled="true"/>
              </el-form-item>
            </el-col>
  
            <el-col :lg="12">
              <el-form-item label="盖板条码" prop="coverCode">
                <el-input v-model="form.coverCode" placeholder="请输入盖板条码" />
              </el-form-item>
            </el-col>
  
            <el-col :lg="12">
              <el-form-item label="夹具编号	" prop="fixtureId">
                <el-input v-model="form.fixtureId" placeholder="请输入夹具编号	" />
              </el-form-item>
            </el-col>
  
            <el-col :lg="12">
              <el-form-item label="焊丝间隙" prop="weldingWireGap">
                <el-input v-model="form.weldingWireGap" placeholder="请输入焊丝间隙" />
              </el-form-item>
            </el-col>
  
            <el-col :lg="12">
              <el-form-item label="压装高度	" prop="pressingHeight">
                <el-input v-model="form.pressingHeight" placeholder="请输入压装高度	" />
              </el-form-item>
            </el-col>
  
            <el-col :lg="12">
              <el-form-item label="错位度 X" prop="misalignmentX">
                <el-input v-model="form.misalignmentX" placeholder="请输入错位度 X" />
              </el-form-item>
            </el-col>
  
            <el-col :lg="12">
              <el-form-item label="错位度 Y" prop="misalignmentY">
                <el-input v-model="form.misalignmentY" placeholder="请输入错位度 Y" />
              </el-form-item>
            </el-col>
  
            <el-col :lg="12">
              <el-form-item label="内陷缺陷" prop="indentationDefect">
                <el-input v-model="form.indentationDefect" placeholder="请输入内陷缺陷" />
              </el-form-item>
            </el-col>
  
            <el-col :lg="12">
              <el-form-item label="工装间隙上" prop="toolingGapUpper">
                <el-input v-model="form.toolingGapUpper" placeholder="请输入工装间隙上" />
              </el-form-item>
            </el-col>
  
            <el-col :lg="12">
              <el-form-item label="工装间隙下" prop="toolingGapLower">
                <el-input v-model="form.toolingGapLower" placeholder="请输入工装间隙下" />
              </el-form-item>
            </el-col>
  
            <el-col :lg="12">
              <el-form-item label="修改时间" prop="updateTime">
                <el-date-picker v-model="form.updateTime" type="datetime" :teleported="false" placeholder="选择日期时间"></el-date-picker>
              </el-form-item>
            </el-col>
  
            <el-col :lg="12">
              <el-form-item label="创建时间" prop="createdTime">
                <el-date-picker v-model="form.createdTime" type="datetime" :teleported="false" placeholder="选择日期时间"></el-date-picker>
              </el-form-item>
            </el-col>
  
            <el-col :lg="12">
              <el-form-item label="IsDeleted" prop="isDeleted">
                <el-radio-group v-model="form.isDeleted">
                  <el-radio v-for="item in options.isDeletedOptions" :key="item.dictValue" :value="item.dictValue">
                    {{item.dictLabel}}
                  </el-radio>
                </el-radio-group>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
        <template #footer v-if="opertype != 3">
          <el-button text @click="cancel">{{ $t('btn.cancel') }}</el-button>
          <el-button type="primary" @click="submitForm">{{ $t('btn.submit') }}</el-button>
        </template>
      </el-dialog>
    </div>
  </template>
  
  <script setup name="dcop70record">
  import { listDcOp70Record,
   addDcOp70Record, delDcOp70Record, 
   updateDcOp70Record,getDcOp70Record, 
   } 
  from '@/api/business/dcop70record.js'
  const { proxy } = getCurrentInstance()
  const ids = ref([])
  const loading = ref(false)
  const showSearch = ref(true)
  const queryParams = reactive({
    pageNum: 1,
    pageSize: 10,
    sort: '',
    sortType: 'asc',
  })
  const columns = ref([
    { visible: true, prop: 'id', label: 'Id' },
    { visible: true, prop: 'coverCode', label: '盖板条码' },
    { visible: true, prop: 'fixtureId', label: '夹具编号	' },
    { visible: true, prop: 'weldingWireGap', label: '焊丝间隙' },
    { visible: true, prop: 'pressingHeight', label: '压装高度	' },
    { visible: true, prop: 'misalignmentX', label: '错位度 X' },
    { visible: true, prop: 'misalignmentY', label: '错位度 Y' },
    { visible: true, prop: 'indentationDefect', label: '内陷缺陷' },
    { visible: true, prop: 'toolingGapUpper', label: '工装间隙上' },
    { visible: true, prop: 'toolingGapLower', label: '工装间隙下' },
    { visible: true, prop: 'updateTime', label: '修改时间' },
    { visible: true, prop: 'createdTime', label: '创建时间' },
    { visible: true, prop: 'isDeleted', label: 'IsDeleted' },
  ])
  const total = ref(0)
  const dataList = ref([])
  const queryRef = ref()
  const defaultTime = ref([new Date(2000, 1, 1, 0, 0, 0), new Date(2000, 2, 1, 23, 59, 59)])
  
  
  var dictParams = [
  ]
  
  
  function getList(){
    loading.value = true
    listDcOp70Record(queryParams).then(res => {
      const { code, data } = res
      if (code == 200) {
        dataList.value = data.result
        total.value = data.totalNum
        loading.value = false
      }
    })
  }
  
  // 查询
  function handleQuery() {
    queryParams.pageNum = 1
    getList()
  }
  
  // 重置查询操作
  function resetQuery(){
    proxy.resetForm("queryRef")
    handleQuery()
  }
  // 自定义排序
  function sortChange(column) {
    var sort = undefined
    var sortType = undefined
  
    if (column.prop != null && column.order != null) {
      sort = column.prop
      sortType = column.order
  
    }
    queryParams.sort = sort
    queryParams.sortType = sortType
    handleQuery()
  }
  
  /*************** form操作 ***************/
  const formRef = ref()
  const title = ref('')
  // 操作类型 1、add 2、edit 3、view
  const opertype = ref(0)
  const open = ref(false)
  const state = reactive({
    single: true,
    multiple: true,
    form: {},
    rules: {
      createdTime: [{ required: true, message: "创建时间不能为空", trigger: "blur"     }],
      isDeleted: [{ required: true, message: "IsDeleted不能为空", trigger: "blur"     }],
    },
    options: {
      // IsDeleted 选项列表 格式 eg:{ dictLabel: '标签', dictValue: '0'}
  isDeletedOptions: [],
    }
  })
  
  const { form, rules, options, single, multiple } = toRefs(state)
  
  // 关闭dialog
  function cancel(){
    open.value = false
    reset()
  }
  
  // 重置表单
  function reset() {
    form.value = {
      id: null,
      coverCode: null,
      fixtureId: null,
      weldingWireGap: null,
      pressingHeight: null,
      misalignmentX: null,
      misalignmentY: null,
      indentationDefect: null,
      toolingGapUpper: null,
      toolingGapLower: null,
      updateTime: null,
      createdTime: null,
      isDeleted: null,
    };
    proxy.resetForm("formRef")
  }
  
  
  // 添加按钮操作
  function handleAdd() {
    reset();
    open.value = true
    title.value = '添加OP70产品入夹具'
    opertype.value = 1
  }
  // 修改按钮操作
  function handleUpdate(row) {
    reset()
    const id = row.id || ids.value
    getDcOp70Record(id).then((res) => {
      const { code, data } = res
      if (code == 200) {
        open.value = true
        title.value = '修改OP70产品入夹具'
        opertype.value = 2
  
        form.value = {
          ...data,
        }
      }
    })
  }
  
  // 添加&修改 表单提交
  function submitForm() {
    proxy.$refs["formRef"].validate((valid) => {
      if (valid) {
  
        if (form.value.id != undefined && opertype.value === 2) {
          updateDcOp70Record(form.value).then((res) => {
            proxy.$modal.msgSuccess("修改成功")
            open.value = false
            getList()
          })
        } else {
          addDcOp70Record(form.value).then((res) => {
              proxy.$modal.msgSuccess("新增成功")
              open.value = false
              getList()
            })
        }
      }
    })
  }
  
  // 删除按钮操作
  function handleDelete(row) {
    const Ids = row.id || ids.value
  
    proxy
      .$confirm('是否确认删除参数编号为"' + Ids + '"的数据项？', "警告", {
        confirmButtonText: proxy.$t('common.ok'),
        cancelButtonText: proxy.$t('common.cancel'),
        type: "warning",
      })
      .then(function () {
        return delDcOp70Record(Ids)
      })
      .then(() => {
        getList()
        proxy.$modal.msgSuccess("删除成功")
      })
  }
  
  
  
  
  
  handleQuery()
  </script>